import {
    GameGSData
} from '../game_for_guosheng/GameGSData';
import { EventKey } from "../common_for_guosheng/Key";
// import { EventKey, StorageKey } from '../common/Key';
import {
    GAMEMODEGS
} from '../game_for_guosheng/GameGSDefine';
import {
    IconData
} from "../ts/ModuleData";
cc.Class({
    extends: require('BaseGSScene'),

    properties: {
        nodBtnStartGame: cc.Node,
        labVersion: cc.Label,
        iconItem: cc.Node,
    },

    onLoad() {
        this.cnmd();
    },

    start() {
        F.GSPartner.sendEvent('场景', {
            '类型': 'home'
        });
        this._registEvent();
        F.GSPartner.createGameClub();
        this.initItemIcon();
    },

    onDestroy() {
        this._unRegistEvent();
        F.GSPartner.hideGameClub();
    },

    _registEvent() {
        F.OnEvent.on(EventKey.EVENT_ENTER_PANEL, this._onTMDShiJianJT, this);
        F.OnEvent.on(EventKey.EVENT_EXIT_PANEL, this._onTMDShiJianJT, this);

    },
    _unRegistEvent() {
        F.OnEvent.off(EventKey.EVENT_ENTER_PANEL, this._onTMDShiJianJT, this);
        F.OnEvent.off(EventKey.EVENT_EXIT_PANEL, this._onTMDShiJianJT, this);
    },

    _onTMDShiJianJT(eventName, param) {
        if (eventName == EventKey.EVENT_ENTER_PANEL) {
            F.GSPartner.hideGameClub();
        } else if (eventName == EventKey.EVENT_EXIT_PANEL) {
            F.GSPartner.showGameClub();
        }
    },

    initItemIcon() {
        let itemObj = this.iconItem.getComponent("IconItem");
        let data = new IconData();
        data.iconUrl = "logo";
        data.iconName = "汽水易购";
        itemObj.setData(data);
    },

    FunMudPListener(button) {
        let name = button.node.name;
        if (name == 'btnStartGame') {
            if (GameGSData.getChallengeData()) {
                F.Ui.openUI('PanelChooseContinue');
            } else {
                GameGSData.setGameMode(GAMEMODEGS.DEFAULT);
                F.Game.loadScene('SceneGame');
            }
        } else if (name == 'btnShare') {
            F.GSPartner.sendEvent('分享', {
                '类型': 'home'
            });
            F.GSPartner.share({
                title: '这一关你能闯过去吗？'
            }, () => {

            });
        } else if (name == 'btnRank') {
            F.GSPartner.sendEvent('打开弹窗', {
                '类型': '排行榜'
            });
            F.Ui.openUI('PanelRank');
        } else if (name == "btnRecord") {
            F.GSPartner.sendEvent('打开弹窗', {
                '类型': '最高纪录'
            });
            F.Ui.openUI('PanelRecord')
        }

    },

    // update (dt) {},
});